<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>景点的CRUD</title>
    <!-- 引入vue包 -->
    <script src="/js/vue.js"></script>
    <!-- 引用element样式 -->
    <link rel="stylesheet" href="/css/index.css">
    <!-- 引用element组件包 -->
    <script src="/js/index.js"></script>
    <!-- 引入axios包--基于vue开发 -->
    <script src="/js/axios.min.js"></script>
</head>
<body>
<div id="app">
    <el-row>
        <!-- 一行分为四列             v-model 将内容和输入双向绑定         -->
        <el-col :span="4">
            <el-input v-model="searchForm.jbcode" size="mini" placeholder="请输入景区级别"></el-input>
        </el-col>
        <el-col :span="4">
            <el-input v-model="searchForm.name" size="mini" placeholder="请输入景区名字关键字"></el-input>
        </el-col>
        <el-col :span="4">
            <el-input v-model="searchForm.oprice" size="mini" placeholder="请输入最优折扣价对应的门市价"></el-input>
        </el-col>
        <el-col :span="4">
            <el-input v-model="searchForm.dprice" size="mini" placeholder="请输入最优折扣价"></el-input>
        </el-col>
        <el-col :span="6">
            &nbsp;&nbsp;<el-button type="success" icon="el-icon-search" @click="search">搜索</el-button>
            &nbsp;&nbsp;<el-button type="primary" icon="el-icon-search" @click="handleAdd">添加</el-button>
            <el-button type="primary" icon="el-icon-refresh" @click="refresh">刷新</el-button>
        </el-col>
        <el-col :span="2"></el-col>
    </el-row>
    <el-table
            :data="tableData"
            style="width: 100%">
        <el-table-column
                prop="id"
                label="景区id"
                align="center"
                width="75px">
        </el-table-column>
        <el-table-column
                prop="code"
                label="景区代码"
                align="center"
                width="90px">
        </el-table-column>
        <el-table-column
                prop="name"
                label="景区名称"
                align="center"
                width="120px">
        </el-table-column>
        <el-table-column label="封面">
            <template slot-scope="scope">
                <el-image
                        style="width: 90px; height: 66px"
                        :src="scope.row.scover"
                ></el-image>
            </template>
        </el-table-column>
        <el-table-column
                prop="themecode"
                label="主题代码"
                align="center"
                width="90px">
        </el-table-column>
        <el-table-column
                prop="seasoncode"
                label="时节代码"
                align="center"
                width="90px">
        </el-table-column>
        <el-table-column
                prop="jbcode"
                label="级别代码"
                align="center"
                width="90px">
        </el-table-column>
        <el-table-column
                prop="yytime"
                label="营业时间"
                align="center"
                width="240px">
        </el-table-column>
        <el-table-column
                prop="areacode"
                label="地域代码"
                align="center"
                width="90px">
        </el-table-column>
        <el-table-column
                prop="saddress"
                label="景区地址"
                align="center"
                width="180px">
        </el-table-column>
        <el-table-column
                prop="taddress"
                label="购票地址"
                align="center"
                width="120px">
        </el-table-column>
        <el-table-column
                prop="lat"
                label="维度"
                align="center"
                width="120px">
        </el-table-column>
        <el-table-column
                prop="lng"
                label="精度"
                align="center"
                width="120px">
        </el-table-column>
        <el-table-column
                prop="mobile"
                label="手机号码"
                align="center"
                width="120px">
        </el-table-column>
        <el-table-column
                prop="phone"
                label="座机号码"
                align="center"
                width="120px">
        </el-table-column>
        <el-table-column
                prop="snav"
                label="导航图"
                align="center"
                width="120px">
        </el-table-column>
        <el-table-column
                prop="summary"
                label="景区简介"
                align="center"
                width="360px">
        </el-table-column>
        <el-table-column
                prop="sintroduction"
                label="景点介绍"
                align="center"
                width="420px">
        </el-table-column>
        <el-table-column
                prop="straffic"
                label="交通指南"
                align="center"
                width="120px">
        </el-table-column>
        <el-table-column label="须知" width="300px">
            <template slot-scope="scope">
                <el-image
                        style="width: 210px; height: 150px"
                       :src="scope.row.snotice"
                ></el-image>
            </template>
        </el-table-column>
        <el-table-column
                prop="sprotocol"
                label="协议"
                align="center"
                width="120px">
        </el-table-column>
        <el-table-column
                prop="isline"
                label="上线"
                align="center"
                width="60px">
        </el-table-column>
        <el-table-column
                prop="weight"
                label="推荐度"
                align="center"
                width="75px">
        </el-table-column>
        <el-table-column
                prop="istodayshow"
                label="每日更新"
                align="center"
                width="90px">
        </el-table-column>
        <el-table-column
                prop="oprice"
                label="最优折扣价对应的门市价 每日更新"
                width="120px">
        </el-table-column>
        <el-table-column
                prop="dprice"
                label="最优折扣价"
                align="center"
                width="120px">
        </el-table-column>
        <el-table-column
                prop="snums"
                label="已消费门票数 时时更新"
                width="120px">
        </el-table-column>
        <el-table-column
                prop="onums"
                label="已下订单数 时时更新"
                width="120px">
        </el-table-column>
        <el-table-column
                prop="smap"
                label="地图"
                align="center"
                width="180px">
        </el-table-column>
        <el-table-column label="操作" width="240px" fixed="right">
            <template slot-scope="scope">
                <el-button
                        @click="handleEdit(scope.$index, scope.row)">更新
                </el-button>
                <el-button
                        type="danger"
                        @click="deleteDept(scope.row.id)">删除
                </el-button>
            </template>
        </el-table-column>
    </el-table>
    <!-- 分页插件 -->
    <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="currentPage"
            :page-sizes="[3, 6, 9, 15 ]"
            :page-size="3"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total">
        <!--current-page 页码
            page-sizes 下拉可以选择 每页条数
            layout 布局
            total 总条数, sizes 就是page-sizes, prev 上一页, pager 详细, next 下一页, jumper 跳转第几页-->
    </el-pagination>
    <!--添加或者更新的form表单-->
    <el-dialog :title="title" :visible.sync="dialogFormVisible">
        <el-form :model="form">
            <el-form-item label="景区代码" :label-width="formLabelWidth">
                <el-input v-model="form.code" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="景区名称" :label-width="formLabelWidth">
                <el-input v-model="form.name" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="景区网址" :label-width="formLabelWidth">
                <el-input v-model="form.scover" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="主题代码" :label-width="formLabelWidth">
                <el-input v-model="form.themecode" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="时节代码" :label-width="formLabelWidth">
                <el-input v-model="form.seasoncode" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="级别代码" :label-width="formLabelWidth">
                <el-input v-model="form.jbcode" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="营业时间" :label-width="formLabelWidth">
                <el-input v-model="form.yytime" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="地域代码" :label-width="formLabelWidth">
                <el-input v-model="form.areacode" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="景区地址" :label-width="formLabelWidth">
                <el-input v-model="form.saddress" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="购票地址" :label-width="formLabelWidth">
                <el-input v-model="form.taddress" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="维度" :label-width="formLabelWidth">
                <el-input v-model="form.lat" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="精度" :label-width="formLabelWidth">
                <el-input v-model="form.lng" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="手机号码" :label-width="formLabelWidth">
                <el-input v-model="form.mobile" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="座机号码" :label-width="formLabelWidth">
                <el-input v-model="form.phone" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="导航图" :label-width="formLabelWidth">
                <el-input v-model="form.snav" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="景区简介" :label-width="formLabelWidth">
                <el-input v-model="form.summary" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="景点介绍" :label-width="formLabelWidth">
                <el-input v-model="form.sintroduction" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="交通指南" :label-width="formLabelWidth">
                <el-input v-model="form.straffic" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="须知" :label-width="formLabelWidth">
                <el-input v-model="form.snotice" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="协议" :label-width="formLabelWidth">
                <el-input v-model="form.sprotocol" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="上线" :label-width="formLabelWidth">
                <el-select v-model="form.isline" placeholder="请选是否上线">
                    <el-option label="更新" value="上线"></el-option>
                    <el-option label="没更新" value="不上线"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="推荐度" :label-width="formLabelWidth">
                <el-input v-model="form.weight" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="每日更新" :label-width="formLabelWidth">
                <el-input v-model="form.istodayshow" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="最优折扣价对应的门市价 每日更新" :label-width="formLabelWidth">
                <el-select v-model="form.oprice" placeholder="请选是否更新">
                    <el-option label="更新" value="0"></el-option>
                    <el-option label="没更新" value="1"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="最优折扣价" :label-width="formLabelWidth">
                <el-input v-model="form.dprice" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="已消费门票数 时时更新" :label-width="formLabelWidth">
                <el-input v-model="form.snums" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="已下订单数 时时更新" :label-width="formLabelWidth">
                <el-input v-model="form.onums" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="地图" :label-width="formLabelWidth">
                <el-input v-model="form.smap" autocomplete="off"></el-input>
            </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button @click="dialogFormVisible = false">取 消</el-button>
            <el-button type="primary" @click="addOrUpdate">确 定</el-button>
        </div>
    </el-dialog>
</div>
<script>
    var vue = new Vue({
        el: "#app",
        data() {
            return {
                tableData: [],//表格格式
                currentPage: 1,//页码
                pageSize: 3,//每页显示数量
                total: 15,//分页总条数
                dialogFormVisible: false,//是否显示对话框
                searchForm: {jbcode: '', name: '', oprice: '', dprice: ''},//封装查询对象
                title: '景区添加',//默认显示title
                form: {
                    code: 0,
                    name: '',
                    scover: '',
                    themecode: 0,
                    seasoncode: 0,
                    jbcode: '',
                    yytime: '',
                    areacode: 0,
                    saddress: '',
                    taddress: '',
                    lat: 0,
                    lng: 0,
                    mobile: '',
                    phone: '',
                    snav: '',
                    summary: '',
                    sintroduction: '',
                    straffic: '',
                    snotice: '',
                    sprotocol: '',
                    isline: 0,
                    weight: 0,
                    istodayshow: 0,
                    oprice: 0,
                    dprice: 0,
                    snums: 0,
                    onums: 0,
                    smap:''
                },//form对象为添加或者更新的form框赋值
            }
        },
        created: function () {//页面初始化,需要执行的业务可以放入该方法
            //调用数据封装方法
            this.loadData();
        },
        methods: {
            //存放多查询数据的方法
            loadData: function () {
                //定义变量_this = this
                var _this = this;
                //axios向后端发送请求
                axios.post('/tScenic/queryByAll', //请求url
                    {
                        "pageNo": this.currentPage, "pageSize": this.pageSize,
                        "data": {
                            "jbcode": this.searchForm.jbcode,
                            "name": this.searchForm.name,
                            "oprice": this.searchForm.oprice,
                            "dprice": this.searchForm.dprice
                        }//携带的参数
                    })//请求的参数 json格式
                    .then(function (response) {//回调函数
                        //前端控制台打印  response  是json对象
                        console.log(response);
                        //JSON.stringify---将JSON对象转换为JSON字符串
                        console.log(JSON.stringify(response))
                        //response 获取后台数据时,一定加 data  response.data 相当于从响应的body中获取
                        if (response.data.code == 200) {
                            //这里面直接写this相当于axios对象，不是vue
                            //（错误的） this.tableData =  response.data.data.list;
                            _this.tableData = response.data.data.list;
                            _this.total = response.data.data.total;
                        }
                    })
                    //axios的异常处理
                    .catch(function (error) {
                        console.log(error);
                    })
            },
            //刷新
            refresh() {
                //原始js重新请求
                location.reload();
            },
            //每页数量发生变化
            handleSizeChange(val) {
                console.log(`每页 ${val} 条`);
                this.pageSize = val;
                //调用加载数据方法
                this.loadData();
            },
            //页码(第几页) 发生变化
            handleCurrentChange(val) {
                console.log(`当前页: ${val}`); //前端控制台打印
                this.currentPage = val;
                //调用加载数据方法
                this.loadData()
            },
            //搜索方法
            search() {
                //调用加载数据方法
                this.loadData();
            },
            //处理更新  index 编号 从0开始, row JSON对象
            handleEdit(index, row) {
                console.log(index, row); //前端控制台打印
                //让对话框显示
                this.dialogFormVisible = true;
                //让title 值也发生变化
                this.title = "更新数据";
                //为form框赋值
                this.form = row;//row JSON对象
            },
            handleAdd() {
                //让对话框显示
                this.dialogFormVisible = true;
                //让title 值也发生变化
                this.title = "景区添加";
                //清空form的值
                this.form = {};//row JSON对象
            },
            //删除方法
            handleDelete(index, row) {
                console.log(index, row);
            },
            addOrUpdate() {
                var url = "/tScenic/add";
                if (this.title == "更新数据") {
                    url = "/tScenic/update";
                }
                //定义变量_this = this
                var _this = this;
                //axios向后端发送请求
                axios.post(url, //请求url
                    this.form)//请求的参数 json格式  form双向绑定 JSON类型数据
                    .then(function (response) {//回调函数
                        //前端控制台打印  response  是json对象
                        console.log(response);
                        //JSON.stringify---将JSON对象转换为JSON字符串
                        console.log(JSON.stringify(response))
                        //response 获取后台数据时,一定加 data  response.data 相当于从响应的body中获取
                        if (response.data.code == 200) {
                            //提示成功
                            _this.$message({
                                message: '恭喜你，这是一条成功消息',
                                type: 'success'
                            });
                            //关闭弹框
                            _this.dialogFormVisible = false;
                            //更新加载数据
                            _this.loadData();
                        } else {
                            _this.$message.error('错了哦，这是一条错误消息');
                        }
                    })
                    //axios的异常处理
                    .catch(function (error) {
                        console.log(error);
                    })
            },
            //处理删除
            deleteDept(id) {
                this.$confirm('此操作将永久删除该部门, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning',
                }).then(() => {
                    var _this = this;
                    axios.delete("/tScenic/delete/"+id)
                        .then(function (response) {
                            console.log(response);
                            if (response.data.code == 200) {
                                _this.$message({
                                    message: '恭喜你，这是一条成功消息',
                                    type: 'success'
                                });
                                _this.dialogFormVisible = false;
                                _this.loadData();
                            } else {
                                this.$message.error('错了哦，这是一条错误消息');
                            }
                        })
                        .catch(function (error) {
                            console.log(error);
                        });
                })
            },
        }
    })
</script>
</body>
</html>